<?php
/**
 * Uri创建类
 *
 * @author fakis738@gmail.com
 * @link http://www.woophp.com/manual/class/uri.lib.php
 * @version $id uri.lib.php v0.1 2011-12-03$
 */
class Uri
{
    const DEF_CONTROLLER = 'index';
    const DEF_METHOD = 'main';
    
    public function __construct($config)
    {
        //是否重写规则
        $this->is_rewritten = $config->item('is_rewritten');
    }
    
    protected function init($config)
    {
        $this->ctrl = $config->item('ctrl');
    }
    
    /**
     * 主要创建Uri方法
     * @access protected
     * @param string $router
     * @param array $params
     * @return string 
     */
    protected function _build_uri($controller, $method, $params = array())
    {
        $uri = '';
        if($this->aUri)
        {
            $uri .= $this->httpDomain;
        }
        if($this->rewrite){
            $uri .= '/'. $this->getCtrlName;
        }else{
            $uri .= '/index.php?m='. $controller. '&amp;a='. $method. '&amp;';
        }
        return $uri;
    }
    
    /**
     * 返回当前Uri
     * @access public
     * @param bool $show 是否绝对地址
     * @return string
     */
    public function current($show = FALSE)
    {
    }
    
    /**
     * 重定向
     * @access public
     * @param string $link 跳转地址
     * @param string $stat http状态码
     */
    public function redirect($link, $stat = '')
    {
        if($stat == '301')
        {
            header('HTTP/1.1 301 Moved Permanently');
        }
        header('Location: '. $link);
        exit;
    }
}

